package com.example.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.ResultCode;
import com.example.dao.*;
import com.example.entity.Jibie;
import com.example.exception.CustomException;
import com.example.service.JibieService;
import com.example.vo.JibieVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Map;

@Service("jibieService")
public class JibieServiceImpl extends ServiceImpl<JibieDao, Jibie> implements JibieService {

    @Resource
    private JibieDao jibieDao;

    public Jibie add(Jibie jibie) {
		
	   //youquchong1
        jibie.setAddtime(new Date());
        jibieDao.insert(jibie);
        return jibie;
    }
	
	
	
    public void delete(Long id) {
        jibieDao.deleteById(id);
    }
	

    public void update(Jibie jibie) {
        //youquchong2
        jibieDao.updateById(jibie);
    }
	
	@Override
    public List<Map<String, Object>> daochuexcel() {
        return jibieDao.daochuexcel();
    }

    @Override
    public Jibie findById(Integer id) {
        return jibieDao.selectById(id);
    }

    public JibieVo findPage(JibieVo jibieVo) {
        LambdaQueryWrapper<Jibie> wrapper = Wrappers.lambdaQuery();
		wrapper.like(ObjectUtils.isNotEmpty(jibieVo.getJibiemingcheng()), Jibie::getJibiemingcheng,jibieVo.getJibiemingcheng());        
        Page<Jibie> page = new Page<>(jibieVo.getCurrent(),jibieVo.getCurrentNum());
        jibieDao.selectPage(page,wrapper);
        List<Jibie> jibies = page.getRecords();
        jibieVo.setList(jibies);
        jibieVo.setPages(page.getPages());
        jibieVo.setTotal(page.getTotal());
        jibieVo.setCurrent(page.getCurrent());
        jibieVo.setCurrentNum(page.getSize());
        return jibieVo;
    }

    @Override
    public void deleteList(List<Jibie> list) {
        List<Integer> ids =  list.stream().map(Jibie::getId).collect(Collectors.toList());
        jibieDao.deleteBatchIds(ids);
    }
	
	
	
	
	
	//youxxianxci
}
